#include "XnccServer.h"
#include "DatagramServer.h"
#include "EventLoop.h"
#include "StreamServer.h"
#include "XnccAddress.h"

namespace xncc {
namespace foundation {
    XnccServer::XnccServer(const std::set<std::string>& list) : blacklist_(list) {}

    XnccServer* XnccServer::CreateXnccServer(EventLoop*                   loop,
                                             std::shared_ptr<XnccAddress> addr,
                                             const std::string&           nameArg,
                                             const std::set<std::string>& blacklist)
    {
        if (addr->Type() == shared::XNCC_ADDR_TYPE::IPV4_TCP || addr->Type() == shared::XNCC_ADDR_TYPE::IPV6_TCP ||
            addr->Type() == shared::XNCC_ADDR_TYPE::UNIX_DOMAIN) {
            return new StreamServer(loop, addr, nameArg, blacklist);
        }
        if (addr->Type() == shared::XNCC_ADDR_TYPE::IPV4_UDP || addr->Type() == shared::XNCC_ADDR_TYPE::IPV6_UDP) {
            return new DatagramServer(loop, addr, nameArg, blacklist);
        }
        if (addr->Type() == shared::XNCC_ADDR_TYPE::SHM) {
            return nullptr;
        }
        return nullptr;
    }

    void XnccServer::Destory(XnccServer* server) { delete server; }
}  // namespace foundation
}  // namespace xncc